<?php
/**
 * Created by PhpStorm.
 * User: hehecat
 * Date: 2018/7/10
 * Time: 13:19
 */

namespace app\api\controller;


use app\api\model\FollowModel;
use app\api\model\UserModel;
use think\Controller;

class Follow extends Controller
{
    /**
     * @title 关注
     * @author hehecat
     * @moudle 关注模块
     *
     * @param userid type:int desc:用户id
     * @param sessionid type:string desc:用户sessionid
     * @param type type:string desc:关注的类型 master|club
     * @param id type:int desc:关注的对象的id
     * @return success desc:是否关注成功 成功返回1 失败返回0
     */
    function follow() {
        $sessionid = input('get.sessionid');
        $type = input('get.type');
        $id = input('get.id');
        $userid = input('get.userid');

        session_start();
        $redis = getRedis();
        if ($sessionid!='' && $sessionid == $redis->get($userid)) {
            $model = new FollowModel();
            $result = $model->follow($type,$id,$userid);
            return json_encode($result);
        }
        return  json_encode(['error'=>'sessionid无效']);
    }

    /**
     * @title 关注列表
     * @author hehecat
     * @moudle 关注模块
     *
     * @param userid type:int desc:用户id
     * @param sessionid type:string desc:用户sessionid
     * @param type type:string desc:关注的类型 master|club
     * @param id type:int desc:关注的对象的id
     * @return success desc:是否关注成功 成功返回1 失败返回0
     */
    function unfollow() {
        $sessionid = input('get.sessionid');
        $type = input('get.type');
        $id = input('get.id');
        $userid = input('get.userid');

        session_start();
        $redis = getRedis();
        if ($sessionid!='' && $sessionid == $redis->get($userid)) {
            $model = new FollowModel();
            $result = $model->unfollow($type,$id,$userid);
            return json_encode($result);
        }
        return  json_encode(['error'=>'sessionid无效']);
    }

    /**
     * @title 关注列表
     * @author hehecat
     * @moudle 关注模块
     *
     * @param userid type:int desc:用户id
     * @param sessionid type:string desc:用户sessionid
     * @param type type:string desc:关注的类型 master|club
     * @param id type:int desc:关注的对象的id
     * @return followlist desc:二维数组 包括了用户对master、club的关注
     */
    function followlist() {
        $userid = input('get.userid');
        $model = new FollowModel();
        $result = $model->followlist($userid);
        return json_encode($result);
    }
}